﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CTMOES;
using CTMOES.Models;

namespace CTMOES.Helper
{
    public class DataHelper
    {
        private static readonly CTMDBEntities _db = new CTMDBEntities();

        public static List<OptionModel> GetOptions(Guid QueID)
        {
            List<Options> options = _db.Options.Where(p => p.QueID == QueID).ToList();
            List<OptionModel> optionList = new List<OptionModel>();
            OptionModel tmp;
            foreach (var op in options)
            {
                tmp = new OptionModel();
                tmp.ID = op.ID;
                tmp.QueID = Guid.Parse(op.QueID.ToString());
                tmp.Description = op.Description;
                optionList.Add(tmp);
            }
            return optionList;
        }

        public static List<QueModel> GetQueList(int Category)
        {
            var questions = _db.Question.Where(q => q.Category == Category).ToList();
            List<QueModel> QueList = new List<QueModel>();
            QueModel tmp;
            foreach (var question in questions)
            {
                tmp = new QueModel();
                tmp.ID = question.ID;
                tmp.Category = Convert.ToInt32(question.Category);
                tmp.ProContent = question.ProContent;
                tmp.OptionList = GetOptions(tmp.ID);
                QueList.Add(tmp);
            }
            return QueList;
        }
        public static List<CTMOES.Subject> AllSubject()
        {
            return _db.Subject.ToList();
        }
        public static List<CTMOES.Paper> GetPaper()
        {
            return _db.Paper.ToList();
        }

    }

}